package net.yunxinyong.cec.controller;

import net.yunxinyong.cec.service.InventoryService;
import net.yunxinyong.cec.utils.CECResult;
import net.yunxinyong.cec.vo.EcnomicInventoryVo;
import net.yunxinyong.cec.vo.RequestVo;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@RestController
@RequestMapping(value = "inventory")
public class InventoryController {

    @Autowired
    private InventoryService inventoryService;

    /**
     * 添加企业详情表
     * @param
     * @return
     */

    @RequestMapping(value = "/detail",method = RequestMethod.POST)
    public CECResult update(@RequestBody RequestVo RequestVo, HttpServletRequest request,
                            HttpServletResponse response){


        EcnomicInventoryVo ecnomicInventoryVo = RequestVo.getDate();
        String cecIdC = null;
        Cookie[] cookies = request.getCookies();
        for (Cookie cookie : cookies) {
            if ("cecId".equals(cookie.getName())) {
                cecIdC = cookie.getValue();
                continue;
            }

            if (!StringUtils.isBlank(cecIdC)) {
                break;
            }
        }
        long id = Long.parseLong(cecIdC);
        /*if (ecnomicInventoryVo.getId() != id){
            return CECResult.build(503,"无权修改当前企业");
        }else {*/
        EcnomicInventoryVo ecnomicInventory = inventoryService.insertAndUpdate(ecnomicInventoryVo);
        if (ecnomicInventory==null){
                return CECResult.build(504,"企业信息修改失败");
            }
            return CECResult.build(200,"企业信息修改成功",ecnomicInventory);
        /*}*/


    }


}
